/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.util.Stack;

/**
 *
 * @author kien.tran
 */
public class BackManager {
    private Stack stack = new Stack();

    public BackManager() {
    }

    public void push(String s){
        if ((s != null) && (s.trim().length() > 0))
            stack.push(s);
    }

    public String pop(){
        String s = "";
        if (!stack.empty()){
            s = stack.pop().toString().trim();
        }
        return s;
    }

    public boolean remove(int items){
        boolean result = true;

        if (stack.size() >= items){
            while (items > 0){
                stack.pop();
                items--;
            }
        } else {
            result = false;
        }
        return result;
    }

    public void removeAll(){
        stack.removeAllElements();
    }

    public int size() {
        return stack.size();
    }
}
